/* 
get
req.query


post
app.use(express.urlencoded({extended:false}))
app.use(express.json())
req.body
*/

const express = require('express');
const app = express();

const HomeRouter=require('./route/HomeRouter')
const LoginRouter=require('./route/LoginRouter')

// 配置解析post参数的中间件-不用下载第三方，内置
app.use(express.urlencoded({extended:false}))  // 解析urlencoded格式的参数,username=zhj&password=123
app.use(express.json())  // 解析json格式的参数  {username:'zhj',password:'123'}

// 应用级别
app.use(function(req,res,next){
    console.log('验证token');
    next()
})

// 应用级别
app.use("/home",HomeRouter)
app.use("/login",LoginRouter)

app.use((req,res)=>{
    res.status(404).send('404 not found')
})

app.get('/',(req,res)=>{
    res.send(req.query)
})

app.listen(3000, () => {
    console.log('Server is running on http://localhost:3000');
})